<?php

//配置信息

class Site extends Admin_Controller {

	public function __construct()
	{
		parent::__construct();
		$this->load->model('site_model');
	}

	public function index ()
	{
		$this->_update_get();
	}
	
	//修改页面
	protected function _update_get()
	{
		$site_list = $this->site_model->get_all();
		
		$custom_site_list = array(); //自定义设置
		$shop_site_list = array(); //商城设置
		$email_site_list = array(); //邮件设置
		$db_site_list = array(); //数据库设置
		
		if ($site_list)
		{
			foreach ($site_list as &$row)
			{
				$row['html'] = $this->_build_html($row);
				switch ($row['category'])
				{
					case 0:
						$custom_site_list[] = $row;
						break;
					case 1:
						$shop_site_list[] = $row;
						break;
					case 2:
						$email_site_list[] = $row;
						break;
					case 3:
						$db_site_list[] = $row;
						break;
				}
			}
		}
		
		$this->template->assign('custom_site_list', $custom_site_list);
		$this->template->assign('shop_site_list', $shop_site_list);
		$this->template->assign('email_site_list', $email_site_list);
		$this->template->assign('db_site_list', $db_site_list);
		$this->template->display('site/update');
	}
	
	//提交修改
	public function _update_post()
	{
		
	}
	
	//组件html
	protected function _build_html($data)
	{
		$html = '';
		
		switch ($data['html_type'])
		{
			case 1:
				$html = '<input type="text" name="'.$data['name'].'" value="'.$data['value'].'" class="input" />';
				break;
			case 2:
				break;
			case 3:
				break;
			case 4:
				break;
			case 5:
				$html = '<textarea name="'.$data['name'].'" class="textarea">'.$data['value'].'</textarea>';
				break;
			case 6:
				$html = editor($data['name'], $data['value'], $data['width'], $data['height'], TRUE);
				break;
			case 7:
				$html = '<input type="file" name="'.$data['name'].'" value="" class="input" />';
				if ($data['value'])
				{
					$html .= '<br /><img src="'.$data['value'].'" width="50" height="50" />';
				}
				break;
		}
		
		return $html;
	}
	
}